<?php
class User_Model_Rightactionmap 
{
 
	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new User_Model_DbTable_Rightactionmap();
	}
	
	public function add($row){
		return $this->_table->insert($row);
	}
	/**
	 * 根据条件获取指定模块信息
	 */
	public function getByCond($cond=array(),$type,$order,$count=20, $offset=0){
		$table = $this->_table->info('name');		
		$select = $this->_table->select()->from($table, $type);
		if(isset($cond['ur_id']) && $cond['ur_id']){
			$select->where('ur_id = ?',$cond['ur_id']);
		}
		if( $type =='count(*)'){
            return $this->_table->getAdapter()->fetchOne($select);
        }
		$select->order($order);
		if($count==0){
			return $this->_table->fetchAll($select);
		}
		$select->limit($count,$offset);
		$rowset = $this->_table->fetchAll($select);
		return $rowset;	
	}
	
	public function getByUrid($ur_id){
		$table = $this->_table->info('name');
		$select = $this->_table->select()->from($table, '*');
		$select->where('ur_id = ?',$ur_id);
		return $this->_table->fetchAll($select)->toArray();
	}
	
	public function getByUraid($ura_id){
		
		$select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table,"*");
        $select->where("1 =?",1);
        $select->where(" ura_id =?",$ura_id);
        $sql=$select->__toString();
		return $this->_table->getAdapter()->fetchAll($sql);
	}
	
	public function deleteBy($ur_id,$ura_id){		
		$where = $this->_table->getAdapter()->quoteInto('ur_id = ?', $ur_id);
		$where .= $this->_table->getAdapter()->quoteInto(' and ura_id = ?', $ura_id);
		$rows_affected = $this->_table->delete($where);
		return $rows_affected;
	}

	
}